const isBrowser = process.browser
export default {
  // 获取书签
  getBookmark () {
    return {
      SQL: 'select * from bookmark order by cjsj',
      Parameter: {}
    }
  },
  // 保存书签
  saveBookmark (bmid, rootid, nodeid, bmname, bmtype, cjsj) {
    if (isBrowser) {
      return [{
        SQL: `replace into bookmark(bmid,rootid,nodeid,bmname,bmtype,cjsj) values(?,?,?,?,?,?)`,
        parameter: {1: bmid, 2: rootid, 3: nodeid, 4: bmname, 5: bmtype, 6: cjsj}
      }]
    } else {
      return [{
        SQL: `replace into bookmark(bmid,rootid,nodeid,bmname,bmtype${cjsj ? ',cjsj' : ''}) values($bmid,$rootid,$nodeid,$bmname,$bmtype${cjsj ? ',$cjsj' : ''})`,
        Parameter: {$bmid: bmid, $rootid: rootid, $nodeid: nodeid, $bmname: bmname, $bmtype: bmtype, $cjsj: cjsj}
      }]
    }
  },
  deleteBookmark (bmid) {
    if (isBrowser) {
      return [{
        SQL: `delete from bookmark where bmid=?;`,
        parameter: {1: bmid}
      }]
    } else {
      return [{
        SQL: `delete from bookmark where bmid=$bmid;`,
        Parameter: {$bmid: bmid}
      }]
    }
  },
  saveHistory (rootid, nodeid, bmtype) {
    if (isBrowser) {
      return [{
        SQL: `replace into bookmark(bmid,rootid,nodeid,bmname,bmtype) values(?,?,?,?,?)`,
        parameter: {1: bmtype, 2: rootid, 3: nodeid, 4: bmtype + '历史纪录', 5: bmtype}
      }]
    } else {
      return [{
        SQL: `replace into bookmark(bmid,rootid,nodeid,bmname,bmtype) values($bmid,$rootid,$nodeid,$bmname,$bmtype)`,
        Parameter: {$bmid: bmtype, $rootid: rootid, $nodeid: nodeid, $bmname: bmtype + '历史纪录', $bmtype: bmtype}
      }]
    }
  }
}
